<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:cgf="http://www.centralgold.com.br/facelets"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="agendaForm">

        <rich:panel>
            <f:facet name="header">Cadastrar Agendamento</f:facet>
			
			<h:panelGrid columns="1">
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Veículo:</ui:define>
					<h:inputText value="#{cadastrarAgenda.automovelSelecionado.marca}/#{cadastrarAgenda.automovelSelecionado.modelo}" 
						readonly="true"
						required="true"
						size="70"/>
					<a:commandButton value="Selecionar" ajaxSingle="true"
						onclick="#{rich:component('modalPesqAutomovel')}.show()"
						reRender="pesqFrotaForm"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Cliente:</ui:define>
					<h:inputText value="#{cadastrarAgenda.clienteSelecionado.nome}" 
						readonly="true"
						required="true"
						size="70"/>
					<a:commandButton value="Selecionar" ajaxSingle="true"
						onclick="#{rich:component('modalPesqCliente')}.show()"
						reRender="pesqClienteForm"/>
				</s:decorate>
				
			</h:panelGrid>
			<h:panelGrid columns="2">
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Data Início:</ui:define>
					<rich:calendar value="#{cadastrarAgenda.agendamentoEdicao.dataInicio}"
						required="true"
						datePattern="dd/MM/yyyy"
						inputSize="10"
						enableManualInput="true"
						showWeekDaysBar="false"
						oninputkeydown="Mascara(this,Data)"
						oninputkeyup="Mascara(this,Data)"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Hora Início:</ui:define>
					<h:inputText value="#{cadastrarAgenda.horaInicio}" 
						maxlength="2"
						required="true"
						size="4"
						onkeydown="Mascara(this,Integer)"
						onkeyup="Mascara(this,Integer)"
						converter="conversorHora"/>:
					<h:inputText value="#{cadastrarAgenda.minutoInicio}" 
						maxlength="2"
						required="true"
						size="4"
						onkeydown="Mascara(this,Integer)"
						onkeyup="Mascara(this,Integer)"
						converter="conversorMinuto"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Data de término:</ui:define>
					<rich:calendar value="#{cadastrarAgenda.agendamentoEdicao.dataFim}"
						required="true"
						datePattern="dd/MM/yyyy"
						inputSize="10"
						enableManualInput="true"
						showWeekDaysBar="false"
						showWeeksBar="false"
						oninputkeydown="Mascara(this,Data)"
						oninputkeyup="Mascara(this,Data)"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Hora de término:</ui:define>
					<h:inputText value="#{cadastrarAgenda.horaFim}" 
						maxlength="2"
						required="true"
						size="4"
						onkeydown="Mascara(this,Integer)"
						onkeyup="Mascara(this,Integer)"
						converter="conversorHora"/>:
					<h:inputText value="#{cadastrarAgenda.minutoFim}" 
						maxlength="2"
						required="true"
						size="4"
						onkeydown="Mascara(this,Integer)"
						onkeyup="Mascara(this,Integer)"
						converter="conversorMinuto"/>
				</s:decorate>
				
				
			</h:panelGrid>
			
			<h:panelGrid columns="1">
				<cgf:inputTextArea name="obs" 
					label="Observação"
					value="#{cadastrarAgenda.agendamentoEdicao.observacao}" 
					tamanhoCampo="500" 
					height="5" 
					size="60" 
					readonly="#{cadastrarAgenda.agendamentoEdicao.usuario ne null and cadastrarAgenda.agendamentoEdicao.usuario.idUsuario ne null and cadastrarAgenda.agendamentoEdicao.usuario.idUsuario ne usuarioLogado.idUsuario}"
					required="false"/>
				<br />
			</h:panelGrid>
			
        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="salvar" value="Salvar" action="#{cadastrarAgenda.salvar()}"
            	onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;"/>
            <h:commandButton id="cancel" value="Cancelar" action="#{cadastrarAgenda.cancelar()}"
            	immediate="true"/>
        </div>

    </h:form>
    
    <rich:modalPanel id="modalPesqAutomovel" height="450" width="800">
          	<f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Pesquisar Frota"></h:outputText>
            </h:panelGroup>
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage value="/img/close.png" styleClass="hidelink" id="hidelink"/>
                <rich:componentControl for="modalPesqAutomovel" attachTo="hidelink" operation="hide" event="onclick"/>
            </h:panelGroup>
        </f:facet>

		<h:form id="pesqFrotaForm">
			<a:region>
				<h:panelGrid columns="2">
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Marca:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.marca}"
							maxlength="50"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Modelo:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.modelo}"
							maxlength="50"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Cor:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.cor}"
							maxlength="20"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Placa:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.placa}"
							maxlength="7"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Chassi:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.chassi}"
							maxlength="50"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Ano Fabricação:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.anoFabricacao}"
							maxlength="4"
							onkeydown="Mascara(this,Integer)"
							onkeyup="Mascara(this,Integer)"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Ano Modelo:</ui:define>
						<h:inputText value="#{cadastrarAgenda.automovelPesquisa.anoModelo}"
							maxlength="4"
							onkeydown="Mascara(this,Integer)"
							onkeyup="Mascara(this,Integer)"/>
					</s:decorate>
				</h:panelGrid>
				<br/>
				<center>
					<a:commandButton value="PESQUISAR" action="#{cadastrarAgenda.pesquisaAutomoveis()}"
						reRender="pesqFrotaForm"/>
				</center>
				<br/><br/>
			</a:region>
			<rich:dataTable value="#{cadastrarAgenda.listaAutomoveis}"
				var="_aut"
				rows="5"
				onRowMouseOver="this.style.backgroundColor='#6495ED'"
       			onRowMouseOut="this.style.backgroundColor='#FFFFCC'"
				id="tabelaAutomoveis">
				<rich:column>
					<f:facet name="header">Marca</f:facet>
					<h:outputText value="#{_aut.marca}"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Modelo</f:facet>
					<h:outputText value="#{_aut.modelo}"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Cor</f:facet>
					<h:outputText value="#{_aut.cor}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Placa</f:facet>
					<h:outputText value="#{_aut.placaFormatada}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Chassi</f:facet>
					<h:outputText value="#{_aut.chassi}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Ano Fabricação</f:facet>
					<h:outputText value="#{_aut.anoFabricacao}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Ano Modelo</f:facet>
					<h:outputText value="#{_aut.anoModelo}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header"></f:facet>
					<a:commandLink value="SELECIONAR"
						action="#{cadastrarAgenda.selecionarAutomovel(_aut)}"
						onclick="#{rich:component('modalPesqAutomovel')}.hide()"
						reRender="agendaForm"/>
				</rich:column>
			</rich:dataTable>
			<rich:datascroller for="tabelaAutomoveis" />
		</h:form>             
    </rich:modalPanel>
    
    <rich:modalPanel id="modalPesqCliente" height="450" width="600">
          	<f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Pesquisar Cliente"/>
            </h:panelGroup>
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage value="/img/close.png" styleClass="hidelink" id="hidelink2"/>
                <rich:componentControl for="modalPesqCliente" attachTo="hidelink2" operation="hide" event="onclick"/>
            </h:panelGroup>
        </f:facet>

		<h:form id="pesqClienteForm">
			<a:region>
				<h:panelGrid columns="2">
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Nome:</ui:define>
						<h:inputText value="#{cadastrarAgenda.clientePesquisa.nome}"
							maxlength="80"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">CPF:</ui:define>
						<h:inputText value="#{cadastrarAgenda.clientePesquisa.cpf}"
							maxlength="14"
							onkeydown="Mascara(this,Cpf)"
							onkeyup="Mascara(this,Cpf)"
							converter="conversorCPF"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Passaporte:</ui:define>
						<h:inputText value="#{cadastrarAgenda.clientePesquisa.passaporte}"
							maxlength="20"
							onkeydown="Mascara(this,Integer)"
							onkeyup="Mascara(this,Integer)"/>
					</s:decorate>
					
					<s:decorate template="/layout/edit.xhtml">
						<ui:define name="label">Número do cartão Gold:</ui:define>
						<h:inputText value="#{cadastrarAgenda.clientePesquisa.nroCartaoGold}"
							maxlength="30"
							onkeydown="Mascara(this,Integer)"
							onkeyup="Mascara(this,Integer)"/>
					</s:decorate>
				</h:panelGrid>
				<br/>
				<center>
					<a:commandButton value="PESQUISAR" action="#{cadastrarAgenda.pesquisaClientes()}"
						reRender="pesqClienteForm"/>
				</center>
				<br/><br/>
			</a:region>
			<rich:dataTable value="#{cadastrarAgenda.listaClientes}"
				var="_cliente"
				rows="5"
				onRowMouseOver="this.style.backgroundColor='#6495ED'"
       			onRowMouseOut="this.style.backgroundColor='#FFFFCC'"
				id="tabelaClientes">
				<rich:column>
					<f:facet name="header">Nome</f:facet>
					<h:outputText value="#{_cliente.nome}"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header">CPF</f:facet>
					<h:outputText value="#{_cliente.cpf}" converter="conversorCPF"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Passaporte</f:facet>
					<h:outputText value="#{_cliente.passaporte}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Número do Cartão Gold</f:facet>
					<h:outputText value="#{_cliente.nroCartaoGold}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header"></f:facet>
					<a:commandLink value="SELECIONAR"
						action="#{cadastrarAgenda.selecionarCliente(_cliente)}"
						onclick="#{rich:component('modalPesqCliente')}.hide()"
						reRender="agendaForm"/>
				</rich:column>
			</rich:dataTable>
			<rich:datascroller for="tabelaClientes" />
		</h:form>             
       </rich:modalPanel>

 </ui:define>
</ui:composition>
